
package com.uchedao.vehicledetection.network.local;

import android.content.Context;
import android.os.AsyncTask;

import com.uchedao.vehicledetection.global.GlobalInfo;
import com.uchedao.vehicledetection.model.Draft;

import java.util.ArrayList;


/**
 * 获取全部草稿
 *
 * @author wushan
 */
public class GetDraftListTask extends AsyncTask<Void, Void, Boolean> {

    private String mError = "读取数据失败";

    private Context mContext = null;

    private boolean mInterrupt = false;

    private IResultListener mResultListener = null;

    private ArrayList<Draft> mDraftList;

    public interface IResultListener {
        void onResult(final boolean success, String error, final ArrayList<Draft> draftList);
    }

    public GetDraftListTask(Context context, IResultListener l) {
        mContext = context;
        mResultListener = l;
    }

    @Override
    protected Boolean doInBackground(Void... params) {
        mDraftList = GlobalInfo.dbHelper.getAllDraft();
        return true;
    }


    public void onCancel() {
        mInterrupt = true;
        cancel(true);
    }

    @Override
    protected void onPostExecute(Boolean result) {
        if (!mInterrupt && mResultListener != null) {
            mResultListener.onResult(result, mError, mDraftList);
        }
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

}
